<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/04/11 20:58:15 $)
// $RCSfile: impex.news.php,v $ : $Revision: 1.4 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

/**
* Return the Total Pages for this Plugin
*/
function getPluginTotalPages8()
{
	return 2;
}

/**
* Run the specific page for plugin
*/
function runPluginPage8($page)
{
	global $dbCore, $_IMPEXHASH, $impexDB;

	// Insert News
	if ($page == 1)
	{
		$newslist = array();
		$impexDB->query("SELECT * FROM `asAnnouncements` ORDER BY `id` ASC;");
		while ($impexDB->nextRecord())
		{
			_impexProcessSlashVariables($impexDB->Record);

			$newslist[$impexDB->Record["id"]] = $impexDB->Record;
		}

		foreach ($newslist as $key=>$val)
		{
			_impexInsertNews($val["subject"], $val["descp"], $val["contents"], $val["dateline"], $val["expiry"]);
	
			displayStatus("Imported News: ".htmlspecialchars($val["subject"]));
		}

	// Insert Subscribers
	} else if ($page == 2) {
		$subscriberslist = array();
		$impexDB->query("SELECT * FROM `asSubscribers` ORDER BY `id` ASC;");
		while ($impexDB->nextRecord())
		{
			_impexProcessSlashVariables($impexDB->Record);

			$subscriberslist[$impexDB->Record["id"]] = $impexDB->Record["email"];
		}

		foreach ($subscriberslist as $key=>$val)
		{
			if (isValidEmail($val))
			{
				_impexInsertSubscriber($val);
				displayStatus("Imported Subscriber: ".htmlspecialchars($val));
			}
		}
	}
}
?>